# -*- coding: utf-8 -*-
"""
@author: wyb
@date: 2023/12/30
@time: 19:21
@desc: Description
"""
from pyquery import PyQuery as pq

# #region css li
# html = '''
# <div>
#     <ul>
#          <li class="item-0">first item</li>
#          <li class="item-1"><a href="link2.html">second item</a></li>
#          <li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li>
#          <li class="item-1 active"><a href="link4.html">fourth item</a></li>
#          <li class="item-0"><a href="link5.html">fifth item</a></li>
#      </ul>
#  </div>
# '''
# doc = pq(html)
# print(doc('li'))
# #endregion
# region css url

# doc = pq(url='https://www.gequbao.com/top/yesterday')
# # print(type(doc('td a')))
# list = doc('td a').items()
# for a in list:
#     print(a.text())

# endregion

# # region css 基本选择器
# html2 = '''
# <div id="container">
#     <ul class="list">
#          <li class="item-0">first item</li>
#          <li class="item-1"><a href="link2.html">second item</a></li>
#          <li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li>
#          <li class="item-1 active"><a href="link4.html">fourth item</a></li>
#          <li class="item-0"><a href="link5.html">fifth item</a></li>
#      </ul>
#  </div>
# '''
#
# doc = pq(html2)
# # print(doc('#container .list li'))
# items = doc('.list')
# list = items.find('li')
# print(list)
# subItems = items.children('.active')
# print(type(subItems))
# for item in subItems.items():
#     print(item.text())
#
# #endregion


html3 = '''
<div class="wrap">
    <div id="container">
        <ul class="list">
             <li class="item-0">first item</li>
             <li class="item-1"><a href="link2.html">second item</a></li>
             <li class="item-0 active"><a href="link3.html"><span class="bold">third item</span></a></li>
             <li class="item-1 active"><a href="link4.html">fourth item</a></li>
             <li class="item-0"><a href="link5.html">fifth item</a></li>
         </ul>
     </div>
 </div>
'''

doc = pq(html3)
# items = doc('.list')
# container = items.parents('.wrap')
# print(type(container))
# print(container)
# li = doc('.list .item-0.active')
# print(li('a').attr('href'))
# # print(li.siblings('.active'))
# print(str(li))

# lis = doc('li').items()
# print(type(lis))
# for li in lis:
#     print(li.text(), type(li))

# alist = doc('a')
# for item in alist.items():
#     print(item.attr.href, item.text(), item.html())

# li = doc('li:first-child')
# print(li)
# li = doc('li:last-child')
# print(li)
li = doc('li:nth-child(2)')
print(li)
li = doc('li:gt(1)')
print(li)
li = doc('li:nth-child(2n)')
print(li)
li = doc('li:contains(second)')
print(li)